{include file="errors.tpl"}
<div class="clr"><br/></div>

<form method="get" name="payments_form" action="{$GLOBALS.site_url}/payments/">
    <input type="hidden" name="action_name" id="action_name" value="" />
    <div class="box" id="displayResults">
        <div class="box-header">
            <div class="actionWithSelected">
                <input type="button" name="action" value="Endorse" class="grayButton" onclick="if ( confirm('Are you sure you want to endorse selected payment(s)?') ) submitForm('endorse');" />
                <input type="button" name="action" value="Delete" class="deletebutton" onclick="if ( confirm('Are you sure you want to delete selected payment(s)?') ) submitForm('delete');" />
            </div>
            <div class="pagination">
                {foreach from=$pages item=page}
                    {if $page == $currentPage}
                        <strong>{$page}</strong>
                    {else}
                        {if $page == $totalPages && $currentPage < $totalPages-3} ... {/if}
                        <a href="?restore=1&amp;page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}{$searchFields}{if $online}&amp;online=1{/if}">{$page}</a>
                        {if $page == 1 && $currentPage > 4} ... {/if}
                    {/if}
                {/foreach}
            </div>
        </div>
        <div class="innerpadding">
            <div id="displayResultsTable">
                <table width="100%">
                    <thead>
                        <tr>
                            <th><input type="checkbox" id="all_checkboxes_control"></th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=sid&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'sid'}DESC{else}ASC{/if}">ID</a>
                            {if $sorting_field == 'sid'}{if $sorting_order == 'ASC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=creation_date&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'creation_date'}DESC{else}ASC{/if}">Date</a>
                            {if $sorting_field == 'creation_date'}{if $sorting_order == 'ASC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            <th>Description</th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=username&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'username'}DESC{else}ASC{/if}">User Name</a>
                            {if $sorting_field == 'username'}{if $sorting_order == 'ASC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=price&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'price'}DESC{else}ASC{/if}">Amount</a>
                            {if $sorting_field == 'price'}{if $sorting_order == 'ASC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                            <th>
                                <a href="?restore=1&amp;sorting_field=status&amp;sorting_order={if $sorting_order == 'ASC' && $sorting_field == 'status'}DESC{else}ASC{/if}">Status</a>
                            {if $sorting_field == 'status'}{if $sorting_order == 'ASC'}<img src="{image}b_down_arrow.gif" />{else}<img src="{image}b_up_arrow.gif" />{/if}{/if}
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {foreach from=$found_payments_sids item=payment_sid name=payments_block}
                        <tr class="{cycle values="oddrow,evenrow"}">
                            <td><input type="checkbox" name="payments[{$payment_sid}]" value="1" id="checkbox_{$smarty.foreach.payments_block.iteration}" /></td>
                            <td>{display property='sid' object_sid=$payment_sid}</td>
                            <td>{display property='creation_date' object_sid=$payment_sid}</td>
                            <td>{display property='name' object_sid=$payment_sid}</td>
                            <td>
                                <a href="{$GLOBALS.site_url}/edit-user/?user_sid={display property='user_sid' object_sid=$payment_sid}">{display property='username' object_sid=$payment_sid}</a>
                            </td>
                            <td>{$GLOBALS.settings.transaction_currency}{display property='price' object_sid=$payment_sid}</td>
                            <td>{display property='status' object_sid=$payment_sid assign=status}{$status}</td>
                        </tr>
                        {/foreach}
                    </tbody>
                    <thead>
                        <tr>
                            <th colspan="5">Total Amount</th>
                            <th colspan="3">{$GLOBALS.settings.transaction_currency}{$total_price}</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="box-footer">
            <div class="actionWithSelected">
                <input type="button" name="action" value="Endorse" class="grayButton" onclick="if (confirm('Are you sure you want to endorse selected payment(s)?')) submitForm('endorse');" />
                <input type="button" name="action" value="Delete" class="deletebutton" onclick="if (confirm('Are you sure you want to delete selected payment(s)?')) submitForm('delete');" />
            </div>
            <div class="pagination">
                {foreach from=$pages item=page}
                    {if $page == $currentPage}
                        <strong>{$page}</strong>
                    {else}
                        {if $page == $totalPages && $currentPage < $totalPages-3} ... {/if}
                        <a href="?restore=1&amp;page={$page}{if $sorting_field ne null}&amp;sorting_field={$sorting_field}{/if}{if $sorting_order ne null}&amp;sorting_order={$sorting_order}{/if}{$searchFields}{if $online}&amp;online=1{/if}">{$page}</a>
                        {if $page == 1 && $currentPage > 4} ... {/if}
                    {/if}
                {/foreach}
            </div>
        </div>
    </div>
</form>

<script>
	var total={$smarty.foreach.payments_block.total};
	{literal}

	function set_checkbox(param) {
		for (i = 1; i <= total; i++) {
			if (checkbox = document.getElementById('checkbox_' + i))
				checkbox.checked = param;
		}
	}
	
	$("#all_checkboxes_control").click(function() {
		if ( this.checked == false)
			set_checkbox(false);
		else
			set_checkbox(true);
	});

	function submitForm(action) {
		document.getElementById('action_name').value = action;
		var form = document.payments_form;
		form.submit();
	}
	{/literal}
</script>